package com.dmxh.result;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> {
    private String code;
    private String message;
    private T data;

    public Result<T> setData(T data) {
        this.data = data;
        return this;
    }

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }

    //成功
    public static Result ok() {
        return new Result(ResultConstant.SUCCESS.getCode(),ResultConstant.SUCCESS.getMessage());
    }

    //错误
    public static Result fail() {
        return new Result(ResultConstant.FAIL.getCode(), ResultConstant.FAIL.getMessage());
    }
    //其他特殊情况
    public static Result response(ResultConstant resultConstant) {
        return new Result(resultConstant.getCode(), resultConstant.getMessage());
    }

}
